package com.lin.manager.sms.service.impl;

import com.lin.manager.sms.enums.SendEnum;
import com.lin.manager.sms.ex.CustomSendException;
import com.lin.manager.sms.model.dto.EmailDto;
import com.lin.manager.sms.model.dto.SmsDTO;
import com.lin.manager.sms.service.SendFaceService;
import com.lin.manager.sms.strategy.SendStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author linjiang
 * @date 2024/8/16
 * @fn
 */
@Service
public class SendFaceServiceImpl implements SendFaceService {

    @Autowired(required = false)
    SendStrategy sendStrategy;

    @Override
    public Boolean sendSms(SmsDTO smsDTO) {
        if (Objects.isNull(sendStrategy)) {
            throw new CustomSendException(SendEnum.SEND_SERVICE_NOT_EXIST);
        }
        return sendStrategy.send(smsDTO);
    }

    @Override
    public Boolean sendEmail(EmailDto emailDto) {
        if (Objects.isNull(sendStrategy)) {
            throw new CustomSendException(SendEnum.SEND_SERVICE_NOT_EXIST);
        }
        return sendStrategy.send(emailDto);
    }
}
